package chapter05

object Demo03_FunctionParameter {
  def main(args: Array[String]): Unit = {
    //可变参数  就是后面加一个*
    def f1(str: String*): Unit = {
      println(str)
    }
    f1("alice")  //WrappedArray(alice)
    f1("aaa","bbb")  //WrappedArray(aaa, bbb)


    //如果参数列表中存在多个参数，那么可变参数一般放置在最后
    def f2(str1: String , str2: String*): Unit = {
      println("str1: " + str1 + "str2: " + str2)
    }
    f2("alice")  //str1: alicestr2: WrappedArray()
    f2("aaa","bbb")  //str1: aaastr2: WrappedArray(bbb)

    //参数默认值，一般将默认值的参数放置在参数列表的后面
    def f3(name: String = "shanxidaxue"): Unit = {
      println("My school is " + name)
    }
    f3("school")  //My school is school
    f3()  //My school is shanxidaxue

    //带名参数
    def f4(name: String = "BFW", age: Int): Unit = {
      println(s"${name}今年${age}岁")
    }
    f4("bob",15)  //bob今年15岁
    f4(age = 45, name = "alice")  //alice今年45岁
    f4(age = 24)  //BFW今年24岁
  }
}
